/**
 * 
 */
package com.sx.feesunit.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ModelDriven;
import com.sx.core.BaseAction;
import com.sx.core.JSONUtils;
import com.sx.feesunit.biz.IAreaBiz;
import com.sx.feesunit.biz.IPaymentsFeeBiz;
import com.sx.feesunit.entity.AreaEntity;
import com.sx.feesunit.entity.PaymentsFeeEntity;
import com.sx.feesunit.exception.SXException;

/**
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
public class PaymentsAction extends BaseAction implements ModelDriven<PaymentsFeeEntity> {
	private IPaymentsFeeBiz ipaymentsbiz;
	private PaymentsFeeEntity paymentsfee = new PaymentsFeeEntity();
	private Log log = LogFactory.getLog(this.getClass());
	//取暖费统计详表
	public String getSummaryInfo() throws SXException{
		String page = "summary";
		try {
			//outJsonString("<h1>111</h1>");
		} catch (Exception e) {
			log.error("取暖费统计详表",e);
			//outJsonString("{}");
			throw new SXException(e);
		}
		return page;
	}
	//获取数据Payments信息
	public void findPaymentInfo() throws SXException{
		try {
			List<PaymentsFeeEntity> list = this.ipaymentsbiz.findPaymentFeesInfo(paymentsfee);
			String str = JSONObject.toJSONString(list);
			outJsonString(str);
		} catch (Exception e) {
			log.error("缴费信息查询And条件出错",e);
			outJsonString("{}");
			throw new SXException(e);
		}
	}
	//查询列表
	public void findPayments() throws SXException{
		String str = "{totalCount:0,data:[]}";
		try{
			List<PaymentsFeeEntity> list = this.ipaymentsbiz.findPaymentFeesInfoByAndCondiction(paymentsfee);
			if(list.size()!=0){
				str = JSONUtils.convertListToJson(PaymentsFeeEntity.class, list, list.get(0).getTotal());
			}
			outJsonString(str);
		}catch(Exception e){
			log.error("缴费信息查询And条件失败出错",e);
			outJsonString(str);
			throw new SXException(e);
		}
	}
	public void addPayments() throws SXException{
		try {
			Integer id = ipaymentsbiz.addPaymentFees(paymentsfee);
			if (id.equals(0)) {
				outJsonString("{success:false,fid:0}");
			} else {
				outJsonString("{success:true,fid:"+id.intValue()+"}");
			}
		} catch (Exception e) {
			log.error("新增费用信息出错",e);
			super.outJsonString("{success:false,pid:0}");
			throw new SXException(e);
			// TODO: handle exception
		}
	}
	public void updatePayments() throws SXException{
		try {
			boolean flag = ipaymentsbiz.updatePaymentFees(paymentsfee);
			if (flag) {
				outJsonString("{success:true}");
			} else {
				outJsonString("{success:false}");
			}
		} catch (Exception e) {
			log.error("修改费用信息出错",e);
			super.outJsonString("{success:false}");
			throw new SXException(e);
			// TODO: handle exception
		}
	}
	public void deletePayments() throws SXException{
		try {
			boolean flag = this.ipaymentsbiz.deletePaymentFees(paymentsfee);
			if (flag) {
				outJsonString("{success:true}");
			} else {
				outJsonString("{success:false}");
			}
		} catch (Exception e) {
			log.error("删除费用信息出错",e);
			super.outJsonString("{success:false}");
			throw new SXException(e);
			// TODO: handle exception
		}
	}
	public PaymentsFeeEntity getModel() {
		// TODO Auto-generated method stub
		return paymentsfee;
	}

	/**
	 * @return the ipaymentsbiz
	 */
	public IPaymentsFeeBiz getIpaymentsbiz() {
		return ipaymentsbiz;
	}

	/**
	 * @param ipaymentsbiz the ipaymentsbiz to set
	 */
	public void setIpaymentsbiz(IPaymentsFeeBiz ipaymentsbiz) {
		this.ipaymentsbiz = ipaymentsbiz;
	}
	
}
